export default class Menu extends Phaser.Scene {
  constructor() {
    super('menu')
    this.player=null
  }

  preload() {
    this.cursors = this.input.keyboard.addKeys('W,A,S,D,space')
    this.game.levelData = {
      //是否双人游戏
      ifDouble: false,
      //关卡数据
      current: 0,
      levels: [
        [1, 7, 3],
        [2, 7, 5],
        [3, 7, 5]
      ]
    }

    console.log(this.registry.levelData)
    if (!this.sys.game.device.os.desktop) {
      this.scale.scaleMode = Phaser.Scale.EXACT_FIT
      this.scale.fullscreenTarget = document.documentElement
      this.scale.startFullscreen()
    }
  }

  create() {
    console.log(this)
    let title = this.add.sprite(0, this.sys.game.config.height / 2, 'menu_title').setOrigin(0.5)
    let text = this.add.text(0, 500, '按空格键开始', { fontSize: '16px', fill: '#fff' }).setOrigin(0.5)
    //添加入场动画
    this.tweens.add({
      targets: [title, text],
      x: this.sys.game.config.width / 2,
      duration: 2000,
      ease: 'none',
      yoyo: false,
      loop: 0
    })

    //在text旁边添加一个小坦克，选择单人还是双人
    this.player = this.add.sprite(-90, 233, 'tank', 9)
    this.tweens.add({
      targets: [this.player],
      x: this.sys.game.config.width / 2 - 90,
      duration: 2000,
      ease: 'none',
      yoyo: false,
      loop: 0
    })




  }

  update() {
    //按下空格键
    if (this.cursors.space.isDown) {
      console.log('space')
      this.scene.start('main')
    }

    //按下W键
    if (this.cursors.W.isDown) {
      //移动player
      this.player.y=233
      this.sys.game.levelData.ifDouble=false
    }
    //按下s键
    if (this.cursors.S.isDown) {
      //移动player
      this.player.y=265
      this.sys.game.levelData.ifDouble=true
    }
  }
}
